package com.shujia.flink.kafka

import org.apache.kafka.clients.producer.{KafkaProducer, ProducerRecord}

import java.util.Properties

object Demo1kafkaProducer {
  def main(args: Array[String]): Unit = {
    /**
     * 1、创建生产者
     *
     */

    val properties = new Properties()

    //指定kafka broker地址
    properties.setProperty("bootstrap.servers", "master:9092,node2:9092,node2:9092")

    //设置key 和value的序列化类
    properties.setProperty("key.serializer", "org.apache.kafka.common.serialization.StringSerializer")
    properties.setProperty("value.serializer", "org.apache.kafka.common.serialization.StringSerializer")

    val producer = new KafkaProducer[String, String](properties)

    /**
     * 2、向kafka中生产数据
     *
     */

    val record = new ProducerRecord[String, String]("test_topic2", "java")

    //发送数据到kafka中
    producer.send(record)
    producer.flush()

    //关闭链接
    producer.close()


  }

}
